﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace Microsoft.Practices.SLUnity.Configuration
{
    public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable {

        //ConfigurationElement, ICollection, IEnumerable
        private ConfigurationElement[] configElements=null;
        //private int Ct;

        public void CopyTo(Array myArr, int index) {

            foreach (ConfigurationElement i in myArr) {
                myArr.SetValue(i, index);
                index = index + 1;
            }

        }
        protected internal ConfigurationElement BaseGet(int index) {
            return configElements[index]; 
        }
        protected internal ConfigurationElement BaseGet(object key) {
            return configElements[1]; 
        }
        protected internal void BaseRemoveAt(int index) {
            return;
        }
        public int Count {
            get {
                return configElements.Length;
            }
        }
        public bool IsSynchronized {
            get {
                return false;//This is not designed to be thread safe
            }
        }
        public Object SyncRoot {
            get {
                return this;
            }
        }
        protected virtual void BaseAdd(ConfigurationElement element) {
        }
        protected internal void BaseAdd(ConfigurationElement element, bool throwIfExists) { }
        protected virtual void BaseAdd(int index, ConfigurationElement element) {
        }
        public IEnumerator GetEnumerator() {
            return new Enumerator(configElements);
        }
        IEnumerator IEnumerable.GetEnumerator() {
            return new Enumerator(configElements);
        }
        protected abstract object GetElementKey(ConfigurationElement element);
        protected abstract ConfigurationElement CreateNewElement();
        protected internal string AddElementName { 
            get{
                return string.Empty;
            }
            set{
                
            }
        }
        protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader) {
            return true;
        }
    }

    public class Enumerator : IEnumerator {
        private ConfigurationElement[] configArr;
        private int Cursor;

        public Enumerator(ConfigurationElement[] configElements) {
            this.configArr = configElements;
            Cursor = -1;

        }

        void IEnumerator.Reset() {
            Cursor = -1;
        }
        bool IEnumerator.MoveNext() {
            if (Cursor < configArr.Length)
                Cursor++;

            return (!(Cursor == configArr.Length));
        }
        object IEnumerator.Current {
            get {
                if ((Cursor < 0) || (Cursor == configArr.Length))
                    throw new InvalidOperationException();
                return configArr[Cursor];
            }
        }

    }

}
